package com.scu.servlet;

import com.scu.dao.AdminDao;
import com.scu.entity.Admin;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet(name = "AddAdminServlet", value = "/AddAdminServlet")
public class AddAdminServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


        String admin_id = request.getParameter("admin_id");
        String name = request.getParameter("name");
        String password = request.getParameter("password");
        String phone = request.getParameter("phone");
        String email = request.getParameter("email");


        Admin admin = new Admin();
        admin.setName(name);
        admin.setAdmin_id(Integer.parseInt(admin_id));//todo
        admin.setPassword(password);
        admin.setPhone(phone);
        admin.setEmail(email);


        System.out.println(admin);
        try {
            new AdminDao().insert(admin);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

    }
}
